/**
 * 系统管理--活动管理的单例对象
 */
var assess = {
    id: "assessTable", //表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    condition: {
    }
};

/**
 * 初始化表格的列
 */
assess.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {
            title: '序号', field: 'number', width: 1, align: 'center', valign: 'middle', formatter: function (value, row, index) {
                return index + 1;
            }
        },
        {title: '租车用户名', field: 'username', align: 'center', valign: 'middle', sortable: true},
        {title: '租车类型', field: 'carType', align: 'center', valign: 'middle', sortable: true},
        {title: '用户评论', field: 'rentAssess', align: 'center', valign: 'middle', sortable: true},
        {title: '请问?', field: 'userId', align: 'center', valign: 'middle', sortable: true, formatter: function(value, row, index){
                return '<button type="button" class="btn btn-xs btn-danger" onclick="assess.toQuestion(\''+row.userId+'\')">请问？</button>'
            }
        }
    ];
};

/**
 * 检查是否选中
 */
assess.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length === 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        assess.seItem = selected[0];
        return true;
    }
};

assess.toQuestion = function () {
    if (!assess.check()) return;
    $("#username").val(assess.seItem.username);
    $("#userId").val(assess.seItem.userId);
    this.layerIndex = layer.open({
        type: 2,
        title: '提问',
        area: ['300px', '300px'],
        fix: false,
        maxmin: true,
        content: Feng.ctxPath + '/question/question_add'
    });
};

$(function () {
    assess.app = new Vue({
        el: '#assessManagerPage',
        data: assess.condition
    });
    var defaultColunms = assess.initColumn();
    var table = new BSTable("assessTable", "/car/see?carId="+Feng.getUrlParam("carId"), defaultColunms);
    table.setPaginationType("client");
    assess.table = table.init();
    laydate.render({
        elem: '#timeLimit',
        range: true,
        theme: '#009efb',
        max: Feng.currentDate()
    });
});
